
{extend name='public/base' /}

{block name="content"}
<style>.layui-table-cell{height: auto!important;}</style>
<div class="layui-col-md12">

    <div class="layui-card">
        <div class="layui-card-header" style="line-height: 55px;">
            <div class="layui-btn-container do_btn">
                <!--按钮区-->
                <button class="layui-btn layui-btn-sm" data-type="add">添加二维码</button>
                <button class="layui-btn layui-btn-sm layui-btn-primary" data-type="reload"><i class="fa fa-refresh"></i> 刷新</button>
            </div>
        </div>
        <div class="layui-card-body">
            <!--表格区-->
            <div class="yys-fluid yys-wrapper">
                <div class="layui-row lay-col-space20">
                    <div class="layui-cos-xs12 layui-col-sm12 layui-col-md12 layui-col-lg12">
                        <section class="yys-body">
                            <div class="yys-body-content clearfix changepwd">
                                <div class="layui-col-lg12 layui-col-md10 layui-col-sm12 layui-col-xs12" style="width:100%">
                                    <div class="user-tables">
                                        <table id="tableFilter" lay-filter="tableFilter"> </table>
                                    </div>
                                </div>
                            </div>
                        </section>
                    </div>
                </div>
            </div>


        </div>
    </div>

</div>

{/block}

{block name="js"} <!--js处理区-->

<script type="text/html" id="action">
    {:widget('common/forms/Delbtn',array('删除二维码',2))}
</script>

<script type="text/html" id="status">
    <input type="checkbox" name="status" value="{{d.id}}" lay-skin="switch" lay-text="开启|关闭" lay-filter="status" {{ d.status == 1 ? 'checked' : '' }}>
</script>


<script type="text/html" id="create_time">
    {{layui.util.toDateString(d.create_time*1000, 'yyyy-MM-dd HH:mm:ss')}}
</script>
<script type="text/html" id="update_time">
    {{layui.util.toDateString(d.update_time*1000, 'yyyy-MM-dd HH:mm:ss')}}
</script>

<script>
    layui.use(['element', 'table', 'form', 'jquery', 'lucky','util'], function () {
        var element = layui.element;
        var form = layui.form;
        var table = layui.table;
        var $ = layui.jquery;
        var lucky=layui.lucky;
        var util=layui.util;

        form.render();

        // layer.load(2);
        table.render({
            elem: '#tableFilter',
            url:"{:url('qrcode')}",
            //toolbar: '#toolbarDemo',
            even: true, //开启隔行背景
            id:'table_id',
            method: 'post',
            page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
                layout: ['limit', 'count', 'prev', 'page', 'next', 'skip','last'] //自定义分页布局
                ,groups: 5 //只显示 1 个连续页码
                ,first: false //不显示首页
                ,last: false //不显示尾页
                ,limit:30
                ,limits:[10,20,30,50]
            },
            text: {
                none: '暂无相关数据'
            },
            cols: [[
                {field: 'id', title: 'ID', width: 80,  sort: true},
                {field: 'name', title: '二维码名字', width: 120},
                {field: 'type', title: '类型', width: 80,templet:'#type',sort:true},
                {field: 'qrcode', title: '二维码', width: 120,templet:function (d) {
                        return '<img  src="'+d.qrcode+'" class="image" style="width: 70px;" alt="无图" />';
                    }},
                {field: 'url', title: 'url', width: 120},
                {field: 'ticket', title: 'ticket', width: 120},
                {field: 'expire_seconds', title: '过期时间', width: 120, sort:true},
                {field: 'status', title: '接入状态', width: 180, templet:'#status',sort:true},
                {field: 'create_time', title: '添加时间', width: 180,templet:'#create_time',sort:true},
                {field: 'update_time', title: '更新时间', width: 180,templet:'#update_time',sort:true},
                {title:'操作',width:60, toolbar: '#action',align:"center"},

            ]],
            done: function (res) {
                layer.closeAll('loading');
            }
        });


        table.on('tool(tableFilter)', function (obj) {
            var data = obj.data;
            var _id=parseInt(data.id);
            var layEvent = obj.event;
            if(layEvent==="del"){
                lucky.Form_Confirm("{:url('qrcodeDel')}",{id:_id},"确认删除二维码？","POST","table_id");
                return false;
            }
        });


        form.on('switch(status)', function(data){
             lucky.Form_Ajax("{:url('qrcodeState')}",{id:data.value},"table_id");
             return false;
        });


        var active = {
            add:function(){
                lucky.CreateForm("添加二维码","40%","50%",'{:url("qrcodeAdd")}','table_id');
                return false;
            },
            reload: function(){
                lucky.CreateReload("table_id");
            }
        };

        $('.do_btn .layui-btn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });


    });


</script>

{/block}